//
//  NSString+Font.m
//  CMClient
//
//  Created by 赵梁 on 9/6/15.
//  Copyright (c) 2015 zify. All rights reserved.
//

#import "NSString+Font.h"

@implementation NSString(Font)

- (CGSize)ZL_sizeWithFont:(UIFont *)font{
    NSDictionary *attributes = @{NSFontAttributeName:font};
    CGSize size = [self sizeWithAttributes:attributes];
    return size;
}

- (CGSize)ZL_sizeWithFont:(UIFont *)font forWidth:(CGFloat)width{
    return [self ZL_sizeWithFont:font forWidth:width lineBreakMode:NSLineBreakByWordWrapping];
}

- (CGSize)ZL_sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(NSLineBreakMode)lineBreakMode{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = lineBreakMode;
    NSDictionary *attributes = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle.copy};
    
    CGSize size = [self boundingRectWithSize:CGSizeMake(width, FLT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
    return size;
}
@end
